//
//  NSString+GX_Base64.m
//  24-加密
//
//  Created by 曹曹 on 16/8/16.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "NSString+GX_Base64.h"

@implementation NSString (GX_Base64)

- (NSString *)base64String {
    // 字符串转成NSData
    NSData *stringData = [self dataUsingEncoding:NSUTF8StringEncoding];
    // NSData进行base64编码, 生成字符串
    NSString *base64String = [stringData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    return base64String;
}
- (NSData *)dataForBase64String {
    return [[NSData alloc] initWithBase64EncodedString:self options:NSDataBase64DecodingIgnoreUnknownCharacters];
}
- (NSString *)stringForBase64 {
    // 根据base64字符串生成NSData
    NSData *base64Data = [self dataForBase64String];
    // 将NSData转成字符串
    NSString *originString = [[NSString alloc] initWithData:base64Data encoding:NSUTF8StringEncoding];
    return originString;
}

@end
